package com.bw.mallshop.timmer;

import android.os.Handler;
import android.os.Message;

import com.bw.mallshop.mvvm.viewmodel.SplashViewModel;

import java.lang.ref.WeakReference;

import androidx.annotation.NonNull;

public class TimeHandler extends Handler {

    private WeakReference<SplashViewModel>weakReference;
    private int time = 3;

    public TimeHandler(SplashViewModel viewModel){
        weakReference = new WeakReference<>(viewModel);
    }

    @Override
    public void handleMessage(@NonNull Message msg) {
        super.handleMessage(msg);
        if (weakReference == null)
            return;
        if (weakReference.get() == null)
            return;
        if (msg.what == 0){
            time -=1;
            weakReference.get().timeObserable.set(""+time+"S");
        }else {
            weakReference.get().skipTimmer();
        }

    }
}
